Public Class frmLogin
    Private db As Database = Database.db

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If db.login(UsernameTextBox.Text, PasswordTextBox.Text) Then
            Me.Hide()
            Form1.Show()
        Else
            MsgBox("sorry wrong username/password")
        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not db.testConnection Then
            Me.Enabled = False
            frmGetDriver.Show()
        End If

        Dim folder As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
        Dim keyFile() As String = IO.Directory.GetFiles(folder, "*.key")
        If keyfile.Length > 0 Then
            Dim email = IO.Path.GetFileNameWithoutExtension(keyFile(0))
            UsernameTextBox.Text = email
        End If
    End Sub

    Private Sub btnCreateAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateAccount.Click
        frmNewUser.Show()
        Me.Hide()
    End Sub
End Class